package com.ruoyi.project.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;

/**
 * 用户信息对象 sys_user
 */
@Accessors(chain = true)
@Data
@AllArgsConstructor
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户账号（手机号）
     */
    @Excel(name = "用户账号", readConverterExp = "手机号")
    private String userName;

    private String password;

    /**
     * 昵称
     */
    @Excel(name = "昵称")
    private String nickName;

    /**
     * 用户邮箱
     */
    @Excel(name = "用户邮箱")
    private String email;

    /**
     * 用户openId
     */
    @Excel(name = "用户openId")
    private String openId;

    /**
     * 余额
     */
    @Excel(name = "余额")
    private Float balance;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP")
    private String loginIp;

    /**
     * 最后登录时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date loginDate;


    /**
     * 角色
     */
    @Excel(name = "角色")
    private Long roleId;

    /**
     * 帐号状态（0正常；1停用）
     */
    @Excel(name = "帐号状态", readConverterExp = "0=正常；1停用")
    private String status;

    /**
     * 删除标志（0代表存在；2代表删除）
     */
    private String delFlag;

    public SysUser() {
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.roleId);
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

}
